// https: // iai.sh.cn/problem/951

#include <bits/stdc++.h>
using namespace std;
struct MEN {
  string name;
  int piao;
};
map<string, int> H;

// 定义小的含义
struct cmp {
  bool operator()(MEN a, MEN b) {
    if (a.piao < b.piao || a.piao == b.piao && a.name > b.name)
      return true;
    return false;
  }
};

priority_queue<MEN, vector<MEN>, cmp>
    Q; // 默认大根堆，但大小的含义在cmp中可以自定义了

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string name;
    cin >> name;

    H[name]++; //  增加票数 
    Q.push(MEN{name, H[name]});
    MEN m = Q.top();
    cout << m.name << endl;
  }

  return 0;
}